package com.hulk.boot.inner.commonservice;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.base.Strings;
import com.hulk.boot.common.util.IdGenIp;
import com.hulk.boot.persistence.mapper.TSequenceMapper;



/**
 * @author  cmt
 *
 */
@Service("sequenceGenerator")
public class SequenceGenerator {

    /**
     * 
     */
    @Autowired
    private TSequenceMapper tSequenceMapper;
   
   
    
    /**
     * @return
     */
    
    public Long getSeq(String seq){
    	return IdGenIp.padSeq(tSequenceMapper.getSequenceNo(seq),18);
    }
    
    public Long getSeq(String seq, int len){
    	return IdGenIp.padSeq(tSequenceMapper.getSequenceNo(seq),len);
    }
    /**
     * @return
     */
    public Long getTxnLogSeq(){
    	return IdGenIp.padSeq(tSequenceMapper.getSequenceNo("S_POS_TXN_LOG"), 18);
    }
    //必须字符串，因为是循环域 long型第一位补全1 会有重复
    public String getLoopTrace6No(){
    	return Strings.padStart(String.valueOf(tSequenceMapper.getSequenceNo("S_POS_LOOP_TRACE6NO")), 6, '0');
    }
    
}
